<%@ page language="java" pageEncoding="UTF-8" buffer="16kb"%>
<%@ include file="/base.jsp"%>
<%@ include file="/module/taglibs.jsp"%>
<%@ include file="/module/nocache.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<%@ include file="/module/js.jsp"%>
<script>
	$(document)
			.ready(
					function() {
						var _form=$("#semesterForm").validate();
						$('#btnBack')
								.click(
										function() {
											document.semesterForm.action = "${basePath}/semesterSummary/recommendStudentIndex";
											document.semesterForm.submit();
										});
						//保存
						$("#btnSave").click(function() {
							if(_form.form()){
							 if(validateSqxm()){	
								//$("#btnSave").attr("disabled","disabled");
								$("#flag").val(1);
								//document.semesterForm.action ="${basePath}/semesterSummary/addRecommendStudent";
			       		  		//document.semesterForm.submit();  
								getReCommendStudentScoreConductCount();
							 }
							}
						});
					  //保存继续新增
						$("#btnSave2").click(function() {
							if(_form.form()){
								 if(validateSqxm()){
							    $("#flag").val(2);
								//$("#btnSave2").attr("disabled","disabled");
								getReCommendStudentScoreConductCount();
// 								  document.semesterForm.action ="${basePath}/semesterSummary/addRecommendStudent";
// 								  document.semesterForm.submit()
								 }
							}
						});
						  //取消
						$("#btnSave3").click(function() {
							  layer.confirm("您是否确定取消?", {icon: 3, title:'提示',skin:'layer-ext-moon'}, function(index){
								  $("#btnSave3").attr("disabled","disabled");
								  document.semesterForm.action ="${basePath}/semesterSummary/addRecommendStudentForward";
								  document.semesterForm.submit();
							  },function(index){
									layer.close(index);
							  });
								
						});
						  //选择
						$("#div1").dialog({
							width : 'auto',
							height : 'auto',
							bgiframe : true,
							modal : true,
							draggable : true,
							resizable : false,
							title : '选择学生',
							autoOpen : false,
						    buttons : {
						    '取消' : function() {
						    	$(this).dialog('close');
							},
							'确定' : function() {
							  if($("#fromSelect").val()==null||$("#fromSelect").val()==""){
								 layer.alert("必须选择一项", {icon: 6});
								 return false;
							  }else{
							    var formSelect = document.getElementById("fromSelect");
							    var str = [];
							    var num=0;
							    for(i=0;i<formSelect.length;i++){
							        if(formSelect.options[i].selected){
							            //str.push(select[i].value);
							            num++;
							        }
							    }
							    if(num>=2){
							     layer.alert("只能选择一项", {icon: 6});
							      return false;
							    }else{
							    	var result = $.parseJSON($("#studentListJson").val());
							    	var xsid=$("#fromSelect").val();
									for (var i = 0; i < result.length; i++) {
										if(xsid==result[i]["xsid"]){
										 $("#xh").val(result[i]["xh"]);
										 $("#xm").val(result[i]["xm"]);
										 $("#xb").val(result[i]["xb"]);
										 $("#bjmc").val(result[i]["bjmc"]);
										 $("#zymc").val(result[i]["zymc"]);
										 $("#njmc").val(result[i]["njmc"]);
										 $("#stuid").val(xsid);
										 $("#bjid").val(result[i]["bjid"]);
										// compareListValue(document.getElementById('zzmm'),result[i].zzmm);
										 break;
										}
									}
									getRecommendStudentScore(xsid);
									  $(this).dialog('close');
							    }
							  }							  
							}
						  }
						});
						  
						  
					});
       function validateSqxm(){
    	   var p1=$('input[name="p"]:checked').val();
    	   var p21=$('input[name="p21"]:checked').val();
    	   var p22=$('input[name="p22"]:checked').val();
    	   var bool=false;
    	   if(p1!=null&&p1!=""){
    		   bool=true;
    	   }
    	   if(p21!=null&&p21!=""){
    		   bool=true; 
    	   }
    	   if(p22!=null&&p22!=""){
    		   bool=true; 
    	   }
    	   if(bool==false){
    		   layer.alert("本学期评审项目至少选一项", {icon: 6});
    		   return false;
    	   }
    	   return bool;
       }
    function showStudentDiv(){
    	 var p1 = $('input[name="p"]:checked').val();
		  var p21 = $('input[name="p21"]:checked').val();
		  var p22 = $('input[name="p22"]:checked').val();
		  if(p1==null&&p21==null&&p22==null){
			  clearData(); 
			  $("#fromSelect").empty();
			  $("#sourseFromSelect2").empty();
		  }
		  if(p1!=null &&p21==null&&p22==null){
			  checkOption(p1);  
		  }else if(p1!=null &&p21!=null&&p22==null){
			  checkOption(p21);  
		  }else if(p1!=null &&p21!=null&&p22!=null){
			  checkOption(p22);   
		  }else if(p1==null&&p21!=null&&p22!=null){
			  checkOption(p22); 
		  }else if(p1==null&&p21!=null&&p22==null){
			  checkOption(p21); 
		  }else if(p1==null&&p21==null&&p22!=null){
			  checkOption(p22); 
		  }else if(p1!=null &&p21==null&&p22!=null){
			  checkOption(p22); 
		  }
         $('#div1').dialog('open');
    }
    function checkOption(value){
      optionRadion();
      var pytype2=null;
      var pytype3=null;
      var pytype=null;
      var flag1=0;
      var flag2=0;
      var flag3=0;
      var p21=$('input[name="p21"]:checked').val();
      var p22=$('input[name="p22"]:checked').val();
      var p=$('input[name="p"]:checked').val();
      if(p21!=null){
    	  flag2=1;  
      }
      if(p22!=null){
    	flag3=1;    
      }
      if(p!=null){
    	if(p=="三好学生"){
         flag1=3;	
    	}else if(p=="好学生"){
    	flag1=2;	
    	}else if(p=="行为达标生"){
    	flag1=1;	
    	}
	  }
     if("三好学生"==value){
    	 clearData();
    	 pytype=3;
     }else if("好学生"==value){
    	 clearData();
    	 pytype=2;
     }else if("行为达标生"==value){
    	 clearData();
    	pytype=1;
     }else if("优秀班干部"==value){
       clearData();
       if(p21!=null&&p22==null){
    	   pytype2=4;
    	   pytype3=null;
       }else if(p21==null&&p22!=null){
    	   pytype3=5;
    	   pytype2=null;
       }else if(p21!=null&&p22!=null){
    	   pytype2=6;
    	   pytype3=6;
       }
     }else if("技能特长生"==value){
    	// var p21=$('input[name="p21"]:checked').val();
       //  var p22=$('input[name="p22"]:checked').val();
         clearData();
         if(p21!=null&&p22==null){
      	 pytype2=4;
      	pytype3=null;
         }else if(p21==null&&p22!=null){
      	 pytype3=5;
      	pytype2=null;
         }else if(p21!=null&&p22!=null){
        	 pytype3=6;
        	 pytype2=6;
         }
     }
     if(pytype!=null&&pytype2==null&&pytype3==null){
    	 $("#pytype").val(pytype); 
     }else if(pytype!=null&&pytype2!=null&&pytype3==null){
    	 $("#pytype").val(pytype2); 
     }else if(pytype!=null&&pytype2==null&&pytype3!=null){
    	 $("#pytype").val(pytype3);
     }else if(pytype!=null&&pytype2!=null&&pytype3!=null){
    	 $("#pytype").val(pytype3); 
     }else if(pytype==null&&pytype2!=null&&pytype3==null){
    	 $("#pytype").val(pytype2); 
     }else if(pytype==null&&pytype2!=null&&pytype3!=null){
    	 $("#pytype").val(pytype3); 
     }else if(pytype==null&&pytype2==null&&pytype3!=null){
    	 $("#pytype").val(pytype3); 
     }
      //处理数据
     $.getJSON("${basePath}/common/getSemesterByStudentConductList?now="+new Date().getTime(),{pytype:$("#pytype").val(),semid :$("#semid").val(),ismanager:$("#ismanager").val(),tjid:null,p:flag1,p21:flag2,p22:flag3},function(data){
			$("#fromSelect").empty();
			$("#sourseFromSelect2").empty();
			//var defaultVal = '';
			//var defaultText = '\u5168\u90e8';
			var _options='';
			//_options=_options+"<option value="+defaultVal+">"+defaultText+"</option>";
			$("#studentListJson").val(JSON.stringify(data));
			for(var i=0;i<data.length;i++){
			 	var val = data[i]["xsid"];
			 	var text = data[i]["xm"];
			 	_options=_options+"<option value="+val+">"+text+"</option>";
			 }
			 $("#fromSelect").html(_options);
		     $("#sourseFromSelect2").html(_options);
		}); 
    }
    function getRecommendStudentScore(xsid){
    	 //处理选择学生的各科课程的成绩
		 var html1="",html2="";
      $.getJSON("${basePath}/common/getSemesterStudentScoreConductList?xsid="+xsid,{semid:$("#semid").val()},
      function(data){
		for(var i=0;i<data.length;i++){
			var kcmc=data[i]["kcmc"]=="undefined" ? "" :data[i]["kcmc"];
			var scorevalue=data[i]["scorevalue"]=="undefined" ? "" :data[i]["scorevalue"];
			html2=html2+"<tr><td class='table-contentTD' style='text-align: center;'>"+(i+1)+"</td><td class='table-contentTD' style='text-align: center;'>"+kcmc+"</td><td class='table-contentTD' style='text-align: center;'>"+scorevalue+"</td></tr>";
		 }
		html1="<table cellpadding='0' cellspacing='0' border='0' class='table-border' width='99%'><tr><td class='table-titleTD' style='text-align: center;'>序号</td><td class='table-titleTD' style='text-align: center;'>课程</td><td class='table-titleTD' style='text-align: center;'>成绩</td></tr>";
		 $("#table_course").html(html1+html2+"</table>");
		});  	
    }
    function getReCommendStudentScoreConductCount(){
    	 var p21=$('input[name="p21"]:checked').val()==null? "":$('input[name="p21"]:checked').val();
	     var p22=$('input[name="p22"]:checked').val()==null? "":$('input[name="p22"]:checked').val();
	    var pxxm=$('input[name="p"]:checked').val()==null ?"" :$('input[name="p"]:checked').val();
    	//var pxxm=$("#p").val()==null ?"" :$("#p").val();
    	//var p21=$("#p21").val()==null ?"" :$("#p21").val();
    	//var p22=$("#p22").val()==null?"":$("#p22").val();
    	if(pxxm!=""||p21!=""||p22!=""){
   		$.ajax({
               type: "post",
               url: "${basePath}/common/getReCommendStudentScoreConductCount",
               data: { bjid :$("#bjid").val(),semid:$("#semid").val(),pxxm1:pxxm,p21:p21,p22:p22},
               dataType: "json",
               success: function(data){
            	   if(data=="1"){
       		  		document.semesterForm.action ="${basePath}/semesterSummary/addRecommendStudent";
       		  		document.semesterForm.submit();  
       		      }else{
       		    	var arrTypes=["三好学生","好学生","行为达标生","优秀班干部","技能特长生"];
       		    	var arrTypesRate=[15,15,80,1,2];
       		       if(data=="2"){
       		    	   layer.alert(arrTypes[0]+"评审项目推荐学生数不能超过班级总人数的"+arrTypesRate[0]+"%", {icon: 6});
        		       return false;	     
       		       }else if(data=="3"){
       		    	 layer.alert(arrTypes[1]+"评审项目推荐学生数不能超过班级总人数的"+arrTypesRate[1]+"%", {icon: 6});
      		       return false;   
       		       }else if(data=="4"){
       		   	 	layer.alert(arrTypes[2]+"评审项目推荐学生数不能超过班级总人数的"+arrTypesRate[2]+"%", {icon: 6});
    		       return false;     
       		       }else if(data=="5"){
       		    	layer.alert(arrTypes[3]+"评审项目每个班级推荐学生数不能超过"+arrTypesRate[3]+"人", {icon: 6});
     		       return false;     
       		       }else if(data=="6"){
       		    	layer.alert(arrTypes[4]+"评审项目每个班级推荐学生数不能超过"+arrTypesRate[4]+"人", {icon: 6});
      		       return false;     
       		       }else{
       		        layer.alert("服务器发生异常", {icon: 6});
        		    return false;
       		       }
       		      }      
               }
  	   		}); 	
    	}else{
    		  layer.alert("评审项目至少选一项", {icon: 6});
  		    return false;
    		//document.semesterForm.action ="${basePath}/semesterSummary/addRecommendStudent";
	  		//document.semesterForm.submit();	
    	}
    }
    
    function clearData(){
     $("#xm").val("");
     $("#stuid").val("");
     $("#xh").val("");
     $("#xb").val("");
     $("#bjmc").val("");
     $("#bjid").val("");
     $("#zymc").val("");
     $("#njmc").val("");
     $("#table_course").html("");
    }
    //选中与反选
 	function optionRadion(){
		  var old = null; //用来保存原来的对象
		    $("input[name='p']").each(function(){//循环绑定事件
		        if(this.checked){
		            old = this; //如果当前对象选中，保存该对象
		        }
		        this.onclick = function(){
		            if(this == old){//如果点击的对象原来是选中的，取消选中
		                this.checked = false;
		                old = null;
		                clearData();
		                $("#fromSelect").empty();
		        		$("#sourseFromSelect2").empty();
		            } else{
		                old = this;
		            }
		        }
		    });
	}     

</script>
</head>
<body>
<input type="hidden" id="studentListJson" name="studentListJson" value=""/>
	<form action="#" id="semesterForm" name="semesterForm">
		<input type="hidden" name="token" value="${token}" />
		<input  type="hidden" id="flag" name="flag" value=""/>
		<input type="hidden" id="pytype" name="pytype" value=""/>
		<input  type="hidden" id="ismanager" name="ismanager" value="${ismanager}"/>
		<input type="hidden"  id="bzr" name="bzr" value="${ismanager}"/>
		<table cellpadding="0" cellspacing="0" border="0" class="table-border"
			width="95%">
			<tr>
			<td class="table-contentTD" style="text-align: left;color:red;font-weight: bold;border: 0" colspan="6">说明：请您先选择评选项目后在选择参评的学生</td>
			</tr>
			<tr>
				<td class="table-header" colspan="6">期末评比推荐表</td>
			</tr>
			<tr>
			<td class="table-titleTD" colspan="6" style="text-align: left;"><font color="red">*</font>本学期评审项目：</td>
			</tr>
			<tr>
			 <td colspan="6" class="table-contentTD" style="color: #000000" >
			  <label><input type="radio" value="三好学生" id="p" name="p" onclick="checkOption(this.value);"/>三好学生</label>
			 <label><input type="radio" value="好学生" id="p" name="p" onclick="checkOption(this.value);"/>好学生</label>
			 <label><input type="radio" value="行为达标生" id="p" name="p" onclick="checkOption(this.value);"/>行为达标生</label>
			 <label><input  type="checkbox" id="p21" name="p21" value="优秀班干部" onclick="checkOption(this.value);" />优秀班干部</label>
			 <label><input type="checkbox" id="p22" name="p22" value="技能特长生" onclick="checkOption(this.value);" />技能特长生</label>
			 </td>
			</tr>
			<tr>
				<td class="table-titleTD" style="width: 12%"><font color="red">*</font>姓名：</td>
				<td class="table-contentTD" style="width: 21%"><input type="text" id="xm" name="xm" value="" placeholder="请输入姓名"   autocomplete="off" readonly="readonly" class="required inputText2"/>&nbsp;&nbsp;
				<input type="button" id="optionBtn" value="选择" class="inputButton"
					onclick="javascript:showStudentDiv();" readonly="readonly"/>
				<input type="hidden" id="stuid" name="stuid" value=""/>
				</td>
				<td class="table-titleTD"  style="width: 12%">学号：</td>
				<td class="table-contentTD" style="width: 21%"><input type="text" id="xh" name="xh" value="" autocomplete="off" readonly="readonly" class="inputText"></td>
				<td class="table-titleTD" style="width: 12%">性别：</td>
				<td class="table-contentTD" style="width: 22%"><input type="text" id="xb" name="xb" value="" autocomplete="off" readonly="readonly" class="inputText"></td>
			</tr>
			<tr>
				<td class="table-titleTD" style="width: 12%">班级：</td>
				<td class="table-contentTD" style="width: 22%"><input type="text" value="" id="bjmc" name="bjmc" readonly="readonly" class="inputText">
				<input type="hidden" id="bjid" name="bjid" value=""/></td>
				<td class="table-titleTD" style="width: 12%">专业：</td>
				<td class="table-contentTD" style="width: 22%"><input type="text" value="" id="zymc" name="zymc" readonly="readonly" class="inputText"></td>
				<td class="table-titleTD" style="width: 12%">年级：</td>
				<td class="table-contentTD" style="width: 22%"><input type="text" value="" id="njmc" name="njmc" readonly="readonly" class="inputText"></td>
			</tr>
			<tr>
				<td class="table-titleTD" style="width: 12%"><font color="red">*</font>学期：</td>
				<td class="table-contentTD" style="width: 22%"><select id="semid" name="semid" class="required selectList" placeholder="请选择学期" onchange="clearData();">
						<option value="">请选择</option>
							<c:forEach items="${semesterList}" var="semester">
								<option value="${semester.xqid}">${semester.xqmc}</option>
							</c:forEach>
				</select></td>
				<td class="table-titleTD" style="width: 12%"><font color="red">*</font>登记时间：</td>
				<td class="table-contentTD" colspan="3" style="width: 22%"><input type="text" value="${currentDate}" id="desj" name="desj" class="required Wdate text inputText2" onFocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" readonly="readonly"></td>
			</tr>
			
			<tr>
		    <td class="table-titleTD">学期成绩：</td>
			<td colspan="5" class="table-contentTD" id="table_course">
			</td>
			</tr>
			<tr>
			<td class="table-titleTD" style="width: 12%"><font color="red">*</font>主要事迹：</td>
			<td colspan="5" class="table-contentTD" style="width: 22%">
			<textarea  id="zysj" name="zysj" style="width: 90%;height: 80px;" placeholder="请输入主要事迹" class="required"></textarea>
			</td>
			</tr>
			<tr>
			<td class="table-titleTD" style="width: 12%"><font color="red">*</font>班委意见：</td>
			<td colspan="5" class="table-contentTD" style="width: 22%">
			<textarea  id="bwyj" name="bwyj" style="width: 90%;height: 80px;" placeholder="请输入班委意见"class="required"></textarea>
			</td>
			</tr>
			<tr>
			<td class="table-titleTD" style="width: 12%"><font color="red">*</font>班主任意见：</td>
			<td colspan="5" class="table-contentTD" style="width: 22%">
			<textarea  id="bzryj" name="bzryj" style="width: 90%;height: 80px;" placeholder="请输入班主任意见" class="required"></textarea>
			</td>
			</tr>
		</table>
		<br />
		<table cellpadding="1" cellspacing="1" border="0" align="left">
			<tr>
			 <c:if test="${ismanager==1}">
			 <kl:permission permisstionList="${permisstionList}" currentUser="${_login_console_user}" currentCatalogId="<%=CatalogUtils.getCatalogId(\"XGGL_QMPB_QMZJ_BZR\")%>" key="add">
				<td><input type="button" id="btnSave" autocomplete="off"  class="inputButton"
					style="text-align: center;" value="保存" autocomplete="off" /></td>
				<td><input type="button" id="btnSave2" autocomplete="off"  class="inputButton"
					style="text-align: center;" value="保存并新增" autocomplete="off" /></td>
			</kl:permission> 
			</c:if>
				<td><input type="button" id="btnSave3" autocomplete="off"  class="inputButton"
					style="text-align: center;" value="取消" autocomplete="off" /></td>
				<td><input type="button" id="btnBack" autocomplete="off"  class="inputButton"
					value="返回" style="text-align: center;" autocomplete="off"/></td>
			</tr>
		</table>
    <div id="div1" style="display: none;">
			<table cellpadding="0" cellspacing="0" border="0" class="table-border">
				  <tr>
				  	 <td style="clear:both; width: 70%">
				  	  <input class="text" name="searchemp" ondblclick="javascript:filterSelectItems('sourseFromSelect2','fromSelect','fromSelect',this.value);"  onkeyup="javascript:filterSelectItems('sourseFromSelect2','fromSelect','fromSelect',this.value);"/><font color="green">在此查找</font> <br/>
				  	   <br/><label style="color:red;">未选中:</label><br/>
				  	   <select name="fromSelect" id="fromSelect" multiple="multiple"  size="1"  multiple="false" style="width:200px; height: 250px;"
							ondblclick="moveField('fromSelect','toSelect');">
						</select>
							<select name="sourseFromSelect2" id="sourseFromSelect2"   multiple="false" style="width: 220px; height: 150px; display: none;" >
  	    </select>
						
					 </td>
  	              </tr>
			</table>
		</div>

	</form>
</body>
	<script type="text/javascript">
	 compareListValue(document.getElementById('semid'),'${semester.xqid}');
	 if("${msg}"!=""){
	       layer.alert("${msg}", {icon: 6});
	  } 
</script>
</html>
